﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using iShoppingBUS;
using iShoppingDTO;

namespace iShopping.Manager.UserControl
{
    public partial class ThongTinSanPham : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if(!IsPostBack)
            {
                FillSanPham();
            }

        }
        public void FillSanPham()
        {
            string maLoaiSanPham = Request.QueryString["MaSanPham"].Trim();
            DataTable dataTable = SanPhamBUS.SelectAll(maLoaiSanPham);

            dataMaLoaiSanPham.Text = maLoaiSanPham;
            if (dataTable.Rows.Count>0)
            {
                dataTenLoaiSanPham.Text = dataTable.Rows[0]["TenLoaiSanPham"].ToString();
            }
            GRSanPham.DataSource = dataTable;
            GRSanPham.DataBind();


        }

        protected void btnHuy_Click(object sender, EventArgs e)
        {
            Response.Redirect("QuanLyLoaiSanPham.aspx", true);		
        }

        protected void btnCapNhap_Click(object sender, EventArgs e)
        {
            string maLoai = dataMaLoaiSanPham.Text.Trim();
            string tenLoai = dataTenLoaiSanPham.Text.Trim();
            if(!string.IsNullOrEmpty(maLoai) && !string.IsNullOrEmpty(tenLoai))
            {
                LoaiSanPhamDTO loaiSanPhamDto = new LoaiSanPhamDTO();
                loaiSanPhamDto.MaLoaiSanPham = maLoai;
                loaiSanPhamDto.TenLoaiSanPham = tenLoai;
                bool res = LoaiSanPhamBUS.UpdateLoaiSanPham(loaiSanPhamDto);
                if(res)
                {
                    FillSanPham();
                }
            }
        }

        protected void GRSanPham_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            GRSanPham.PageIndex = e.NewPageIndex;
            FillSanPham();
        }
    }
}